import { AbsSvgUnitParser } from "../absunitparser"
import line from "../../../../../canvas/common/struct/basestruct/polyline.js";
import lgxcom from '../../../../../canvas/common/common'
import globalconst from "../../../../../canvas/common/globalConst";
var global = globalconst.GlobalConst;

class LineParser extends AbsSvgUnitParser{
    constructor(){
        super();
        this.type = global.BaseUnitPolyline<<16;
    }
    parse(mainEle){
        let unitInfo = new line.Polyline();
        unitInfo.type = this.type;

        let p1 = new lgxcom.LGXPoint();
        let p2 = new lgxcom.LGXPoint();
        const attributes = mainEle.attributes;
        for (let i = 0; i < attributes.length; i++) {
            const attr = attributes[i];
            if (attr.name == 'x1') {
                p1.x = parseFloat(attr.value);
            }
            else if (attr.name == 'y1') {
                p1.y = parseFloat(attr.value);
            }
            else if (attr.name == 'x2') {
                p2.x = parseFloat(attr.value);
            }
            else if (attr.name == 'y2') {
                p2.y = parseFloat(attr.value);
            }
        }
        this.parseCommonProp(unitInfo,mainEle);
        this.chg2SysCoord(p1);
        this.chg2SysCoord(p2);
        unitInfo.pos.addPoint(p1);
        unitInfo.pos.addPoint(p2);
        unitInfo.strPosition = unitInfo.pos.toString();
        return unitInfo;
    }
}

export {LineParser}